class GuideExec < ActiveRecord::Base
  def self.set_guide_map g
    ges = GuideExec.find_by_sql("select * from guide_execs as ge where date_format(ge.created_at,'%Y-%m-%d') = '#{Time.now.strftime('%Y-%m-%d')}' and ge.guide_id = #{g.id}")
    if ges.size > 0
      ge = ges[0]
      if g.num.to_i > ge.need_num.to_i
        ge.update_attributes({:need_num =>g.num,:status => '1'})
      end
    else
      ge = GuideExec.new
      ge.guide_id = g.id
      ge.guide_name = g.name
      ge.need_num = g.num
      ge.status = '0'
      ge.guide_type = g.g_type
      ge.guide_cycle = g.cycle
      ge.guide_url = g.url
      ge.guide_weigh = g.weigh
      ge.save
    end    
  end

  def self.set_guide_other
    gs = Guide.find :all, :conditions => ['status = 1']
    gs.each do |g|
      ge = GuideExec.new
      ge.guide_id = g.id
      ge.guide_name = g.name
      ge.need_num = g.num
      ge.status = '0'
      ge.guide_type = g.g_type
      ge.guide_cycle = g.cycle
      ge.guide_url = g.url
      ge.guide_weigh = g.weigh
      ge.save
    end
  end
end
